/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package myutil;

import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author Tidus Le
 */
public class myRender extends DefaultTableCellRenderer
{
    public void fillColor(JTable t,JLabel l,boolean isSelected )
    {
        if(isSelected){
            l.setBackground(t.getSelectionBackground());
            l.setForeground(t.getSelectionForeground());
        }
        else{
            l.setBackground(t.getBackground());
            l.setForeground(t.getForeground());
        }
    }
    
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
     {
        if(value instanceof JLabel){
            JLabel label = (JLabel)value;
            setText(label.getText());
            setIcon(label.getIcon());
            label.setOpaque(true);
            fillColor(table,label,isSelected);
            return label;
        }
        else
            return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
     }
}
